﻿using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using PublicDomain.Data.Csv;
using PublicDomain.Data.Csv.Metadata;
using PublicDomain.Framework.UnitTesting;
using PublicDomain.Framework.UnitTesting.DataDrivenTest;

namespace PublicDomain.UnitTest.Data.Csv
{
    [TestClass]
    [DeploymentItem("CsvDefaultFile.csv")]
    public class CsvDataReaderTest
    {
        public TestContext TestContext { get; set; }

        public void TestInitialize()
        {
        }

        [TestMethod]
        [Description("Tests constructor CsvDataReader(string csvFilePath, CsvDataFormat csvDataFormat).")]
        public void CsvDataReaderConstructor1Test()
        {
            var csvDataFormat = new CsvDataFormat();

            var target = new CsvDataReader("CsvDefaultFile.csv", csvDataFormat);

            Assert.IsNotNull(target.TextReader);
            Assert.IsTrue(target.IsClosed);
            Assert.IsNotNull(target.CsvDataFormat);
            Assert.AreEqual(csvDataFormat.CsvColumnsDefinitions.Count, target.FieldCount);
        }

        [TestMethod]
        [Description("Tests constructor CsvDataReader(string csvFilePath).")]
        public void CsvDataReaderConstructor2Test()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");

            Assert.IsNotNull(target.TextReader);
            Assert.IsTrue(target.IsClosed);
            Assert.IsNull(target.CsvDataFormat);
        }

        [TestMethod]
        [Description("Tests constructor CsvDataReader(TextReader textReader, CsvDataFormat csvDataFormat).")]
        public void CsvDataReaderConstructor3Test()
        {
            var csvDataFormat = new CsvDataFormat();
            var streamReader = new StreamReader("CsvDefaultFile.csv");

            var target = new CsvDataReader(streamReader, csvDataFormat);

            Assert.AreSame(streamReader, target.TextReader);
            Assert.IsTrue(target.IsClosed);
            Assert.AreEqual(csvDataFormat.CsvColumnsDefinitions.Count, target.FieldCount);
        }

        [TestMethod]
        [Description("Tests constructor CsvDataReader(TextReader textReader).")]
        public void CsvDataReaderConstructor4Test()
        {
            var streamReader = new StreamReader("CsvDefaultFile.csv");

            var target = new CsvDataReader(streamReader);

            Assert.AreSame(streamReader, target.TextReader);
            Assert.IsTrue(target.IsClosed);
            Assert.IsNull(target.CsvDataFormat);
        }

        [TestMethod]
        [Description("Tests constructor CsvDataReader(TextReader textReader) in the case if argument 'textReader' is null.")]
        public void CsvDataReaderConstructor4TextReaderIsNullTest()
        {
            AssertExtensions.ThrowsArgumentNullException(
                () => new CsvDataReader((StreamReader)null),
                "textReader");
        }

        [TestMethod]
        [Description("Tests property CsvDataReader.IsClosed.")]
        public void IsClosedTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");

            var isClosed = target.IsClosed;

            Assert.IsTrue(target.IsClosed);
        }

        [TestMethod]
        [Description("Tests property CsvDataReader.FieldCount.")]
        public void FieldCountTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            var fieldCount = target.FieldCount;

            Assert.AreEqual(-1, fieldCount);
        }

        [TestMethod]
        [Description("Tests property CsvDataReader.Depth.")]
        public void DepthTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");

            var depth = target.Depth;

            Assert.AreEqual(0, depth, "For the CSV data readers the depth of nesting for the current row is always '0'.");
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.Read().")]
        public void ReadTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");

            var count = 0;
            while (target.Read())
            {
                count++;
            }

            Assert.AreEqual(1, count); // The file CsvDefaultFile.csv has 1 record with skipping the header by default
            Assert.IsTrue(target.IsClosed, "If there is no more records, the property IsClosed should be set to 'true'.");
            Assert.AreSame(TextReader.Null, target.TextReader, "If there is no more records, the property TextReader should be set to TextReader.Null with no data.");
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.Close().")]
        public void CloseTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");

            target.Close();

            Assert.IsTrue(target.IsClosed, "After Close the property IsClosed should be set to 'true'.");
            Assert.AreSame(TextReader.Null, target.TextReader, "After Close the property TextReader should be set to TextReader.Null with no data.");
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.Dispose().")]
        public void DisposeTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            target.Dispose();
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetSchemaTable().")]
        [DeploymentItem("GetValueTestCsvFile.csv")]
        public void GetSchemaTableTest()
        {
            var target = TestDataFactory.GetTestFileCsvDataReader("GetValueTestCsvFile.csv");

            Assert.IsTrue(target.Read());

            var actual = target.GetSchemaTable();

            Assert.IsNotNull(actual);
            Assert.AreEqual(target.CsvDataFormat.CsvColumnsDefinitions.Count, actual.Rows.Count);
            for (int i = 0; i < actual.Rows.Count; i++)
            {
                var columnsSchema = target.CsvDataFormat.CsvColumnsDefinitions[i];
                var row = actual.Rows[i];

                Assert.AreEqual(row["ColumnName"], columnsSchema.ColumnName);
                Assert.AreEqual(row["ColumnOrdinal"], columnsSchema.ColumnOrdinal);
                Assert.AreEqual(row["ColumnSize"], columnsSchema.ColumnSize);
                Assert.AreEqual((DbType)row["DataType"], columnsSchema.DataType);
            }
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.NextResult().")]
        [ExpectedException(typeof(NotImplementedException))]
        public void NextResultTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            target.NextResult();
        }

        [TestMethod]
        [Description("Tests property CsvDataReader.RecordsAffected().")]
        public void RecordsAffectedTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.AreEqual(-1, target.RecordsAffected, "For CSV files data reader RecordsAffected has to be set always to -1.");
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetDataTypeName(int j).")]
        public void GetDataTypeNameTest()
        {
            foreach (DbType dataType in Enum.GetValues(typeof(DbType)))
            {
                var csvDataFormat = new CsvDataFormat();
                csvDataFormat.CsvColumnsDefinitions.Add(new CsvColumnDefinition { ColumnName = "Column1", ColumnOrdinal = 0, DataType = dataType });

                var target = new CsvDataReader("CsvDefaultFile.csv", csvDataFormat);

                var expected = Enum.GetName(typeof(DbType), dataType);
                var actual = target.GetDataTypeName(0);

                Assert.AreEqual(expected, actual);
            }
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetName(int j).")]
        public void GetNameTest()
        {
            var csvDataFormat = new CsvDataFormat();

            var csvColumn1Schema = new CsvColumnDefinition { ColumnName = "Column1", ColumnOrdinal = 0, DataType = DbType.Boolean };
            csvDataFormat.CsvColumnsDefinitions.Add(csvColumn1Schema);

            var target = new CsvDataReader("CsvDefaultFile.csv", csvDataFormat);

            var expected = csvColumn1Schema.ColumnName;
            var actual = target.GetName(csvColumn1Schema.ColumnOrdinal);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetOrdinal(string name).")]
        public void GetOrdinalTest()
        {
            var csvDataFormat = new CsvDataFormat();

            var csvColumn1Schema = new CsvColumnDefinition { ColumnName = "Column1", ColumnOrdinal = 0, DataType = DbType.Boolean };
            csvDataFormat.CsvColumnsDefinitions.Add(csvColumn1Schema);

            var target = new CsvDataReader("CsvDefaultFile.csv", csvDataFormat);

            var expected = csvColumn1Schema.ColumnOrdinal;
            var actual = target.GetOrdinal(csvColumn1Schema.ColumnName);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetBoolean(int j).")]
        public void GetBooleanTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = true;
            var actual = target.GetBoolean(1);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetBoolean(int j) in the case of closed data reader.")]
        public void GetBooleanDataReaderIsClosedTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");

            AssertExtensions.Throws<CsvDataInvalidOperationException>(
                () => { target.GetBoolean(1); },
                "Data reader is closed.");
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetByte(int j).")]
        public void GetByteTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = 255;
            var actual = target.GetByte(9);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetBytes(int j, long fieldOffset, byte[] buffer, int bufferoffset, int length).")]
        public void GetBytesTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var textLength = 5;
            var expectedReturnResult = textLength * 2;
            var expectedBytes = new byte[10] { 66, 0, 67, 0, 120, 0, 121, 0, 122, 0 };
            var actualBytes = new byte[10];

            var actualReturnResult = target.GetBytes(12, 1, actualBytes, 0, textLength);

            AssertExtensions.Equals(expectedBytes, actualBytes);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetChar(int j).")]
        public void GetCharTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = 'p';
            var actual = target.GetChar(11);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetChars(int j, long fieldoffset, char[] buffer, int bufferoffset, int length).")]
        public void GetCharsTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var textLength = 9;
            var expectedReturnResult = textLength;
            var expectedChars = new char[9] { 'o', 'r', 'e', 'm', 'I', 'p', 's', 'u', 'm' };
            var actualChars = new char[9];

            var actualReturnResult = target.GetChars(13, 1, actualChars, 0, textLength);

            AssertExtensions.Equals(expectedChars, actualChars);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetData(int j).")]
        [ExpectedException(typeof(NotImplementedException))]
        public void GetDataTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            var value = target.GetData(0);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetDateTime(int j).")]
        public void GetDateTimeTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = new DateTime(1961, 4, 12);
            var actual = target.GetDateTime(8);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetDecimal(int j).")]
        public void GetDecimalTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = 1567234.987654321M;
            var actual = target.GetDecimal(3);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetDouble(int j).")]
        public void GetDoubleTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = 123.321D;
            var actual = target.GetDouble(2);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataRow.GetFieldType(int j) for all positive cases.")]
        [DeploymentItem("CsvDataReaderTestData.mdb")]
        [DataSource("System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\CsvDataReaderTestData.mdb", "GetFieldTypeTestData", DataAccessMethod.Sequential)]
        public void GetFieldTypeTest()
        {
            var dataDrivenTest = new DataDrivenTest<GetFieldTypeTestParams, GetFieldTypeTestExpectedResults>(this.TestContext);

            dataDrivenTest.ExecuteTest(() =>
            {
                var csvDataFormat = new CsvDataFormat
                    {
                        CsvColumnsDefinitions = new Collection<CsvColumnDefinition>
                        {
                            new CsvColumnDefinition { ColumnOrdinal = 0, ColumnName = "Column0", DataType = dataDrivenTest.TestParams.DbType }
                        }
                    };

                var target = new CsvDataReader("CsvDefaultFile.csv", csvDataFormat);

                var expected = dataDrivenTest.ExpectedResults.Type;
                var actual = target.GetFieldType(0);

                Assert.AreEqual(expected, actual);
            });
        }

        [TestMethod]
        [Description("Tests method CsvDataRow.GetFieldType(int j) for the case when DbType is out of the scope.")]
        public void GetFieldTypeDbTypeIsOutOfScopeTest()
        {
            DbType outOfScopeDbType = (DbType)(Enum.GetValues(typeof(DbType)).Cast<DbType>().Last().ToInt32() + 1);

            var csvDataFormat = new CsvDataFormat
            {
                CsvColumnsDefinitions = new Collection<CsvColumnDefinition>
               {
                    new CsvColumnDefinition { ColumnOrdinal = 0, ColumnName = "Column0", DataType = outOfScopeDbType }
               }
            };

            var target = new CsvDataReader("CsvDefaultFile.csv", csvDataFormat);

            AssertExtensions.Throws<CsvDataInvalidOperationException>(
                () => { target.GetFieldType(0); },
                String.Format(CultureInfo.CurrentCulture, "The DbType '{0}' is not mapped on a .NET Type.", outOfScopeDbType));
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetFloat(int j).")]
        public void GetFloatTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = 123.4567F;
            var actual = target.GetFloat(4);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetGuid(int j).")]
        public void GetGuidTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = new Guid("EF26D86E-FC44-4E79-B077-2E205996D071");
            var actual = target.GetGuid(10);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetInt16(int j).")]
        public void GetInt16Test()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = Int16.MaxValue;
            var actual = target.GetInt16(5);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetInt32(int j).")]
        public void GetInt32Test()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = Int32.MinValue;
            var actual = target.GetInt32(6);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetInt64(int j).")]
        public void GetInt64Test()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = Int64.MaxValue;
            var actual = target.GetInt64(7);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetString(int j).")]
        public void GetStringTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var actual = target.GetString(0);

            Assert.AreEqual("text1", actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetString(int j) in the case of closed data reader.")]
        public void GetStringDataReaderIsClosedTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");

            AssertExtensions.Throws<CsvDataInvalidOperationException>(
                () => { target.GetString(0); },
                "Data reader is closed.");
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetValue(int j).")]
        [DeploymentItem("GetValueTestCsvFile.csv")]
        public void GetValueTest()
        {
            var target = TestDataFactory.GetTestFileCsvDataReader("GetValueTestCsvFile.csv");

            Assert.IsTrue(target.Read());

            for (int i = 0; i < target.CsvDataFormat.CsvColumnsDefinitions.Count; i++)
            {
                var columnSchema = target.CsvDataFormat.CsvColumnsDefinitions[i];

                var expected = columnSchema.Tag;
                var actual = target.GetValue(i);

                Assert.IsNotNull(actual);
                Assert.AreEqual(expected, actual, String.Format(columnSchema.ToString()));
            }
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetValues(object[] values) in the case when array length is the same as number of CSV columns.")]
        [DeploymentItem("GetValueTestCsvFile.csv")]
        public void GetValuesLengthEqualsColumnCountTest()
        {
            var target = TestDataFactory.GetTestFileCsvDataReader("GetValueTestCsvFile.csv");

            Assert.IsTrue(target.Read());

            var actualValues = new object[target.CsvDataFormat.CsvColumnsDefinitions.Count];
            var actualCount = target.GetValues(actualValues);

            Assert.AreEqual(target.CsvDataFormat.CsvColumnsDefinitions.Count, actualCount);

            for (int i = 0; i < actualCount; i++)
            {
                var columnSchema = target.CsvDataFormat.CsvColumnsDefinitions[i];

                var expectedValue = columnSchema.Tag;
                var actualValue = actualValues[i];

                Assert.IsNotNull(actualValue);
                Assert.AreEqual(expectedValue, actualValue, String.Format(columnSchema.ToString()));
            }
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetValues(object[] values) in the case when array length is less them number of CSV columns.")]
        [DeploymentItem("GetValueTestCsvFile.csv")]
        public void GetValuesLengthLessThenColumnCountTest()
        {
            var target = TestDataFactory.GetTestFileCsvDataReader("GetValueTestCsvFile.csv");

            Assert.IsTrue(target.Read());

            var actualValues = new object[1];
            var actualCount = target.GetValues(actualValues);

            Assert.AreEqual(actualValues.Length, actualCount);

            for (int i = 0; i < actualCount; i++)
            {
                var columnSchema = target.CsvDataFormat.CsvColumnsDefinitions[i];

                var expectedValue = columnSchema.Tag;
                var actualValue = actualValues[i];

                Assert.IsNotNull(actualValue);
                Assert.AreEqual(expectedValue, actualValue, String.Format(columnSchema.ToString()));
            }
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetValues(object[] values) in the case when array length is greater then number of CSV columns.")]
        [DeploymentItem("GetValueTestCsvFile.csv")]
        public void GetValuesLengthGreaterThenColumnCountTest()
        {
            var target = TestDataFactory.GetTestFileCsvDataReader("GetValueTestCsvFile.csv");

            Assert.IsTrue(target.Read());

            var actualValues = new object[target.CsvDataFormat.CsvColumnsDefinitions.Count + 1];
            var actualCount = target.GetValues(actualValues);

            Assert.AreEqual(target.CsvDataFormat.CsvColumnsDefinitions.Count, actualCount);

            for (int i = 0; i < actualCount; i++)
            {
                var columnSchema = target.CsvDataFormat.CsvColumnsDefinitions[i];

                var expectedValue = columnSchema.Tag;
                var actualValue = actualValues[i];

                Assert.IsNotNull(actualValue);
                Assert.AreEqual(expectedValue, actualValue, String.Format(columnSchema.ToString()));
            }
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetValues(object[] values) in the case when array length is zero.")]
        [DeploymentItem("GetValueTestCsvFile.csv")]
        public void GetValuesLengthIsZeroTest()
        {
            var target = TestDataFactory.GetTestFileCsvDataReader("GetValueTestCsvFile.csv");

            Assert.IsTrue(target.Read());

            var actualValues = new object[0];
            var actualCount = target.GetValues(actualValues);

            Assert.AreEqual(actualValues.Length, actualCount);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetValues(object[] values) in the case of array values is null.")]
        [DeploymentItem("GetValueTestCsvFile.csv")]
        public void GetValuesIsNull()
        {
            var target = TestDataFactory.GetTestFileCsvDataReader("GetValueTestCsvFile.csv");

            Assert.IsTrue(target.Read());

            AssertExtensions.ThrowsArgumentNullException(
                () => target.GetValues(null),
                "values");
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.IsDBNull(int j).")]
        public void IsDBNullTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var actual = target.IsDBNull(14);

            Assert.AreEqual(true, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.this[string name].")]
        [DeploymentItem("GetValueTestCsvFile.csv")]
        public void IndexerStringTest()
        {
            var target = TestDataFactory.GetTestFileCsvDataReader("GetValueTestCsvFile.csv");

            Assert.IsTrue(target.Read());

            for (int i = 0; i < target.CsvDataFormat.CsvColumnsDefinitions.Count; i++)
            {
                var columnSchema = target.CsvDataFormat.CsvColumnsDefinitions[i];

                var expected = columnSchema.Tag;
                var actual = target[columnSchema.ColumnName];

                Assert.IsNotNull(actual);
                Assert.AreEqual(expected, actual, String.Format(columnSchema.ToString()));
            }
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.this[int j].")]
        [DeploymentItem("GetValueTestCsvFile.csv")]
        public void IndexerIntTest()
        {
            var target = TestDataFactory.GetTestFileCsvDataReader("GetValueTestCsvFile.csv");

            Assert.IsTrue(target.Read());

            for (int i = 0; i < target.CsvDataFormat.CsvColumnsDefinitions.Count; i++)
            {
                var columnSchema = target.CsvDataFormat.CsvColumnsDefinitions[i];

                var expected = columnSchema.Tag;
                var actual = target[i];

                Assert.IsNotNull(actual);
                Assert.AreEqual(expected, actual, String.Format(columnSchema.ToString()));
            }
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.ValidateStatusIsClosed(int j).")]
        public void ValidateStatusIsClosedTest()
        {
            AssertExtensions.Throws<CsvDataInvalidOperationException>(
                () =>
                {
                    var target = new CsvDataReader_Accessor("CsvDefaultFile.csv");

                    target.ValidateStatusIsClosed();
                },
                "Data reader is closed.");
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetSByte(int j).")]
        public void GetSByteTest()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = SByte.MinValue;
            var actual = target.GetSByte(18);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetUInt16(int j).")]
        public void GetUInt16Test()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = UInt16.MaxValue;
            var actual = target.GetUInt16(15);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetUInt32(int j).")]
        public void GetUInt32Test()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = UInt32.MaxValue;
            var actual = target.GetUInt32(16);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [Description("Tests method CsvDataReader.GetUInt64(int j).")]
        public void GetUInt64Test()
        {
            var target = new CsvDataReader("CsvDefaultFile.csv");
            Assert.IsTrue(target.Read());

            var expected = UInt64.MaxValue;
            var actual = target.GetUInt64(17);

            Assert.AreEqual(expected, actual);
        }

        private class GetFieldTypeTestParams
        {
            [DataTableColumnName("TestParamDbType")]
            public DbType DbType { get; set; }
        }

        private class GetFieldTypeTestExpectedResults
        {
            [DataTableColumnName("ExpectedResultTypeName")]
            public Type Type { get; set; }
        }
    }
}
